<?php
namespace ImiDemo\WebSocketDemo\MainServer\Listener;

use Imi\ConnectContext;
use Imi\Event\EventParam;
use Imi\Util\AtomicManager;
use Imi\Event\IEventListener;
use Imi\Bean\Annotation\Listener;

/**
 * @Listener("IMI.SERVER.GROUP.LEAVE")
 */
class GroupLeave implements IEventListener
{
    /**
     * 事件处理方法
     * @param EventParam $e
     * @return void
     */
    public function handle(EventParam $e)
    {
        $people = AtomicManager::sub('users');
        $e->getData()['server']->groupCall($e->getData()['groupName'], 'push', ConnectContext::get('username') . ' 离开了，在线人数：' . $people);
    }
}